﻿// See https://aka.ms/new-console-template for more information
// 启动模块

using AOT.Game.Timer;
using Net.Msg;
using Net.Public.Client;
using Net.Public.EventSystem;
using Net.Public.Helper;
using Net.Public.Msg;
using Net.Public.Server;


internal class Program
{
    public static void Main(string[] args)
    {
        bool isOpen = false;
        RpcServer server = new RpcServer();
        RpcClient client = new RpcClient();
        ScriptTimer timer = new ScriptTimer();
        ThreadPool.QueueUserWorkItem((obj) =>
        {
            while (isOpen)
            {
                timer.Tick();
            }
        });
        isOpen = true;
        RpcEventSystem.Instance.RegisterMsg(EMsgType.TestMsg, (msg) =>
        {
            TestMsg testMsg = (TestMsg)msg;
            Console.WriteLine("收到服务器消息：" + testMsg.Content);
        });
        while (isOpen)
        {
            string input = Console.ReadLine();
            if (input.Equals("begin"))
            {
                server.OnStart(timer, "127.0.0.1", 8088, 100);
                client.OnStart(timer, "127.0.0.1", 8088);
            }

            if (input.Equals("test"))
            {
                TestMsg msg = new TestMsg();
                msg.Content = "客户端你好";
                BaseMsg testMsg = new BaseMsg(msg, EMsgType.TestMsg);
                server.BroadcastMsgToClients(testMsg);
            }
        }
    }
}